package com.lagou.edu.controller;

import com.lagou.edu.service.IUserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author stevejson
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService userService;

    @RequestMapping(value = "/register/{email}/{password}/{code}", method = RequestMethod.POST)
    public boolean register(@PathVariable String email, @PathVariable String password, @PathVariable String code, HttpServletResponse response){
        return userService.register(response, email, password, code);
    }

    @RequestMapping(value = "/isRegistered/{email}", method = RequestMethod.GET)
    public boolean isRegistered(@PathVariable String email){
        return userService.isRegistered(email);
    }

    @RequestMapping(value = "/login/{email}/{password}", method = RequestMethod.POST)
    public String login(@PathVariable String email, @PathVariable String password, HttpServletResponse response){
        return userService.login(response, email, password);
    }

    @RequestMapping(value = "/info/{token}", method = RequestMethod.GET)
    public String info(@PathVariable String token){
        return userService.info(token);
    }

}
